package com.hj.service.impl;


import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.scheduling.annotation.Scheduled;

import com.hj.dao.CompanyMapper;
import com.hj.dao.ReSetMapper;
import com.hj.entity.Company;
import com.hj.entity.Cti_humanservice;
import com.hj.entity.Cti_ivrservice;
import com.hj.entity.Cti_routeservice;
import com.hj.entity.Ss_accesscode;
import com.hj.entity.Vcc_uptnum;
import com.hj.service.ReSetService;
import com.hj.utils.Arrayutil;
import com.hj.utils.MultipleDataSource;
import com.hj.utils.Removeall;

@Service("resetservice")
public class ReSetServiceImpl implements ReSetService{
	
	@Autowired
	private ReSetMapper resetmapper;
	
	@Autowired
	private CompanyMapper companymapper;
	
	@Value("${cp.agency.need.closedown}")
	private String agencyNames;

	@Value("${cp.agency.need.ignore}")
	private String  agencyNameIgnores;

	public void ResetJob() {
		/*String[] agency = agencyNames.split(",");
		String[] agencyIgnores = agencyNameIgnores.split(",");
		int rn;//记录400号码长度以便定义数组
		String[] num=new String[2000];
		String[] num1=new String[2000];
		*//*查询停机状态的400号码*//*
		MultipleDataSource.setDataSourceKey("dataSource");
		List<Ss_accesscode> list_sac=resetmapper.search_ac();
		MultipleDataSource.setDataSourceKey("dataSource1");
		for(int i=0;i<list_sac.size();i++){
			num[i]=list_sac.get(i).getVccId();
		}
		//查询到停机并且余额大于0的自有用户
		List<Company> cp=resetmapper.search_cp(num);
		MultipleDataSource.setDataSourceKey("dataSource2");
		//查询到停机并且截止日大于当前日期的代理商用户
		List<Company> bcp=companymapper.search_cp(agency,agencyIgnores,num);
		cp.addAll(bcp);
		if(!cp.isEmpty()){
			//先更改company表状态
			companymapper.update_companyReset(cp);
			//删除num中元素
			Removeall.remove(num);
			for(rn=0;rn<cp.size();rn++){
				if(cp.get(rn).getCallee_number().length()>4){
					num[rn]=cp.get(rn).getVccid();
				}
			}
			//将num数据copy到num_c中(缩减数组长度)
			String [] num_c=new String[rn];
			rn=0;
			for(int i=0;i<num_c.length;i++){
				num_c[i]=num[i];
			}
			Removeall.remove(num);
			*//*List<Ss_accesscodecopy> sacc=resetmapper.search_sacc(num_c);*//*
			MultipleDataSource.setDataSourceKey("dataSource");
			*//*for(int i=0;i<sacc.size();i++){
				resetmapper.update_sacc(sacc.get(i));//查询备份表停机前状态，逐个复机
				num1[i]=sacc.get(i).getVccId();
			}*//*
			//新建一个数组保存未复机的号码
			String[] restnum1=new String[num_c.length];
			restnum1=num_c;
			for(int k=0;k<restnum1.length;k++){
				if(restnum1[k]!=null){
					restnum1[k]="4001".concat(restnum1[k]);
				}
				else{
					restnum1[k]="";
				}
			}
			//查询在业务节点的400号码
			List<Vcc_uptnum> vun=resetmapper.search_vun(restnum1);
			Removeall.remove(num1);
			for(int i=0;i<vun.size();i++){
				if(vun.get(i).getAccNumber().length()>4){
				num1[i]=vun.get(i).getAccNumber().substring(4);
				}
			}
			//对业务节点复机
			resetmapper.update_un(num1);
			for(int k=0;k<restnum1.length;k++){
				if(restnum1[k].length()>4){
					restnum1[k]=restnum1[k].substring(4);
				}
			}
			//新建restnum2保存未复机的400号码
			String[] restnum2=new String[restnum1.length];
			restnum2=Arrayutil.removesame(restnum1,num1);
			//查询按路由设置的400号码
			List<Cti_routeservice> c_rs=resetmapper.search_crs(restnum2);
			//清空num1
			Removeall.remove(num1);
			for(int i=0;i<c_rs.size();i++){
				num1[i]=c_rs.get(i).getVccid();
			}
			//复机按路由设置的400号码
			for(int i=0;i<c_rs.size();i++){
			resetmapper.update_rs(c_rs.get(i));
			}

			String[] restnum3 = new String[restnum2.length];

				restnum3 = Arrayutil.removesame(restnum2, num1);

				List<Cti_ivrservice> c_is = resetmapper.search_is(restnum3);
				Removeall.remove(num1);
				for (int i = 0; i < c_is.size(); i++) {
					num1[i] = c_is.get(i).getVccId();
					//ivr服务逐个复机
					resetmapper.update_is(c_is.get(i));
				}

			String[] restnum4=new String[restnum3.length];

				restnum4 = Arrayutil.removesame(restnum3, num1);
				List<Cti_humanservice> s_hs = resetmapper.search_hs(restnum4);
				System.out.print(s_hs.size());
				Removeall.remove(num1);
				for (int i = 0; i < s_hs.size(); i++) {
					//num1[i]=s_hs.get(i).getVccId();
					//人工服务复机
					resetmapper.update_hs(s_hs.get(i));
				}

		}
		System.out.println("自有用户和代理商用户复机完");*/
	}
}


